package com.xkstream.client.nim;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xkstream.client.entity.BetRank;
import com.xkstream.client.nim.CustomAttachment;
import com.xkstream.client.nim.CustomAttachmentType;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by admin on 2017/4/10.
 */

public class BetRankAndNumAttachment extends CustomAttachment {
    List<BetRank> ranks;
    int onlineNum;
    int anchorStatus;

    public BetRankAndNumAttachment() {
        super(CustomAttachmentType.BETRANKANDNUM);
    }

    public List<BetRank> getRanks() {
        return ranks;
    }

    public void setRanks(List<BetRank> ranks) {
        this.ranks = ranks;
    }

    public int getOnlineNum() {
        return onlineNum;
    }

    public void setOnlineNum(int onlineNum) {
        this.onlineNum = onlineNum;
    }

    public int getAnchorStatus() {
        return anchorStatus;
    }

    public void setAnchorStatus(int anchorStatus) {
        this.anchorStatus = anchorStatus;
    }

    @Override
    public void parseData(String str) {
        try {

            JSONObject jsonObj = new JSONObject(str);
            if(jsonObj.has("betRank")){
                String betRankStr = jsonObj.getString("betRank");
                ranks = new Gson().fromJson(betRankStr,new TypeToken<List<BetRank>>() {
                }.getType());
            }
            if(jsonObj.has("onlineNum")){
                onlineNum = jsonObj.getInt("onlineNum");
            }
            if(jsonObj.has("anchor_status")){
                anchorStatus = jsonObj.getInt("anchor_status");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public JSONObject packData() {
        return null;
    }
}
